#!/usr/bin/env python
# coding: utf-8
#

from wxbot import *
import requests


class MyWXBot(WXBot):

    login_config = False

    def set_login_config(self, config):
        self.login_config = config

    def handle_msg_all(self, msg):
        request = self.login_config
        if msg['msg_type_id'] == 4 and msg['content']['type'] == 0:
            request['msg'] = msg['content']['data']
            request['name'] = msg['user']['name']
            res = requests.post('https://node.zkong.me/faceless/project_robot',data=request)
            json = res.json()
            if json['status']==1:
                self.send_msg_by_uid(json['data']['response'], msg['user']['id'])
        elif msg['msg_type_id'] == 3 and msg['content']['type'] == 0:
            request['msg'] = msg['content']['desc']
            request['name'] = msg['user']['name']
            res = requests.post('https://node.zkong.me/faceless/project_robot',data=request)
            json = res.json()
            if json['status']==1:
                self.send_msg_by_uid(json['data']['response'], msg['user']['id'])

def main():
    bot = MyWXBot()
    bot.DEBUG = True
    bot.conf['qr'] = 'tty'
    bot.run()


if __name__ == '__main__':
    main()
